package cn.shyouchi.wuguanjia.android.ui.trainstatistic;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import cn.shyouchi.wuguanjia.android.R;
import cn.shyouchi.wuguanjia.android.widget.CircularProgressBar;

/**
 * Created by Eenie on 2017/3/30 at 14:56
 * Email: 472279981@qq.com
 * Des:
 */

public class TrainStatisticAdapter extends BaseQuickAdapter<TrainStatistEntity, BaseViewHolder> {
    public TrainStatisticAdapter(List<TrainStatistEntity> data) {
        super(R.layout.item_train_statistic_layout, data);
    }

    @Override
    protected void convert(BaseViewHolder holder, TrainStatistEntity entity) {


        holder.setText(R.id.tv_person_name, entity.getName());

        for (TrainStatistEntity.InfoBean infoBean : entity.getInfo()) {

            if (infoBean.getType() == 1) {
                fillMaster(holder, infoBean);
            } else if (infoBean.getType() == 2) {
                fillPost(holder, infoBean);
            }


        }


    }


    private void fillMaster(BaseViewHolder holder, TrainStatistEntity.InfoBean infoBean) {
        CircularProgressBar bar = holder.getView(R.id.pro_master_rate);

        bar.setProgress((int) infoBean.getSchedule());

        holder.setText(R.id.tv_master_rate, String.format("%s%%", infoBean.getSchedule()));


    }

    private void fillPost(BaseViewHolder holder, TrainStatistEntity.InfoBean infoBean) {
        CircularProgressBar bar = holder.getView(R.id.pro_post_rate);

        bar.setProgress((int) infoBean.getSchedule());

        holder.setText(R.id.tv_post_rate, String.format("%s%%", infoBean.getSchedule()));
    }


}
